home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / math / gle-3.000 / gle-3 / gle / miss_os2.c < prev    next >
C/C++ Source or Header  |  1995-03-08  |  4KB  |  153 lines

  1. /*----------------------------------------------------------------------------*/
  2. /*                    additional stuff for OS/2                               */
  3. /*                      Axel Rohde June 1994                                  */
  4. /*----------------------------------------------------------------------------*/
  5.  
  6. #define INCL_DOSSESMGR
  7. #define INCL_DOSMISC
  8. #define INCL_DOSPROCESS
  9. #define INCL_WINWINDOWMGR
  10. #define INCL_WINSYS
  11.  
  12. #include <os2emx.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16.  
  17. #define PATH "PATH"
  18.  
  19. char *SearchPath(char *Name)
  20. {
  21.   ULONG         rc;
  22.   static char   ResultBuffer[640];
  23.   const  UCHAR *PathPointer;
  24.  
  25.         rc = DosScanEnv(PATH, &PathPointer);
  26.         if (rc != 0)
  27.                 return NULL;
  28.  
  29.         rc = DosSearchPath(SEARCH_CUR_DIRECTORY + SEARCH_ENVIRONMENT, 
  30.                            PATH,
  31.                            Name,
  32.                            ResultBuffer,
  33.                            sizeof(ResultBuffer)
  34.                           );
  35.         if (rc != 0)
  36.                 return NULL;
  37.         else 
  38.                 return ResultBuffer;
  39. }
  40.  
  41. ULONG startPMSession(void)
  42. {
  43.  #ifdef SURFACE
  44.   extern char outputName[80];
  45.  #endif
  46.  
  47.   UCHAR         PgmName[256];
  48.   UCHAR         PgmInputs[256];
  49.   UCHAR         ObjBuf[100];
  50.  
  51.   STARTDATA     startDat;       /* Session start information                */
  52.   ULONG         SessionID;      /*  Session and Process ID for new session, */
  53.                                 /*  ULONG for GCC */
  54.   PID           ProcessID; 
  55.   USHORT        rc;
  56.  
  57.   /* ---- init startDat struct defaults */
  58.   startDat.Length       = sizeof(STARTDATA);
  59.   startDat.Related      = SSF_RELATED_CHILD;
  60.   startDat.FgBg         = SSF_FGBG_FORE;
  61.   startDat.TraceOpt     = SSF_TRACEOPT_NONE;
  62.   startDat.PgmTitle     = NULL;
  63.  
  64.  #ifdef SURFACE
  65.   strcpy(PgmInputs, "SURFOS2.TMP /D -B /O ");
  66.   strcat(PgmInputs, outputName);
  67.  #else
  68.   strcpy(PgmInputs, "/draw gleos2.tmp");
  69.  #endif
  70.   startDat.PgmInputs    = PgmInputs;
  71.  
  72.   startDat.TermQ        = NULL;
  73.   startDat.Environment  = NULL;
  74.   startDat.InheritOpt   = SSF_INHERTOPT_PARENT;
  75.   startDat.SessionType  = SSF_TYPE_PM;
  76.   startDat.PgmControl   = SSF_CONTROL_VISIBLE;
  77.   startDat.InitXPos     = 0;
  78.   startDat.InitYPos     = 0;
  79.   startDat.InitXSize    = 0;
  80.   startDat.InitYSize    = 0;
  81.   startDat.IconFile     = 0;
  82.   startDat.PgmHandle    = 0;
  83.   startDat.Reserved     = 0;
  84.   startDat.ObjectBuffer = ObjBuf;
  85.   startDat.ObjectBuffLen = 100;
  86. #ifdef SURFACE
  87.   startDat.PgmName      = SearchPath("SURF_PM.EXE");
  88. #else
  89.  #ifdef FILLPATH
  90.   startDat.PgmName      = SearchPath("GLE_PM.EXE");
  91.  #else
  92.   startDat.PgmName      = SearchPath("GLE_PMF.EXE");
  93.  #endif
  94. #endif
  95.  
  96.   if (startDat.PgmName == NULL)
  97.         return 0;
  98.  
  99.   rc = DosStartSession(&startDat, &SessionID, &ProcessID);
  100.   if ( rc == 0)
  101.         return SessionID;
  102.   else return 0;
  103. }
  104.  
  105. ULONG stopPMSession(ULONG SessID)
  106. {
  107.  DosStopSession(STOP_SESSION_SPECIFIED, SessID);
  108. }
  109.  
  110. #ifdef PM
  111. int peekMsg(void)
  112. {
  113.         extern HAB hab;
  114.         extern QMSG qmsg;
  115.  
  116.         if (WinPeekMsg(hab, &qmsg, 0, 0, 0, PM_NOREMOVE))
  117.                 {
  118.                 WinGetMsg(hab, &qmsg, 0, 0, 0);
  119.                 WinDispatchMsg(hab, &qmsg);
  120.                 }
  121. }
  122. #else
  123. int peekMsg(void)
  124. {
  125. }
  126. #endif
  127.  
  128.  
  129. #ifdef SURFACE
  130.  
  131. /* error file stuff for surf_pm */
  132.  
  133. FILE *openErrFile(char *fname)
  134. {
  135.         FILE *fptr;
  136.  
  137.         unlink(fname);
  138.         fptr = fopen(fname,"w");
  139.         if (fptr==NULL)
  140.                {
  141.                 perror("Unable to open output file GLEOS2.ERR");
  142.                 return NULL;
  143.                }
  144.         else return fptr;
  145. }
  146.  
  147. int closeErrFile(FILE *errfile)
  148. {
  149.         if (fclose(errfile)!=0) 
  150.                 perror("Unable to close output file GLEOS2.ERR");
  151. }
  152. #endif /* SURFACE */
  153.